package com.wyd.qxglht.controller;

import java.util.List;

import javax.annotation.Resource;

import com.wyd.qxglht.dao.IModulesDao;
import com.wyd.qxglht.model.Modules;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/modules")
public class ModulesController {



       @Resource
      private IModulesDao modulesDao;

      @ApiOperation(value = "添加模块",notes="添加模块")
      
   
      @PostMapping(value="add")
        
        public Modules add(@RequestBody Modules u) {
            
        
        
            return modulesDao.save(u);
            
        }


        
    @ApiOperation(value="根据编号修改模块信息",notes = "根据编号修改模块信息")
    @ApiImplicitParams({
      @ApiImplicitParam(name="id",value ="模块编号",required=true,paramType ="path"),
      @ApiImplicitParam(name="name",value ="模块名称",required=true,paramType ="path"),
      @ApiImplicitParam(name="parentId",value ="父编号",required=true,paramType ="path"),
      @ApiImplicitParam(name="path",value ="路径",required=true,paramType ="path"),
      @ApiImplicitParam(name="weight",value ="权重",required=true,paramType ="path")
     
      
  })
  @PutMapping(value = "/edit/{id}/{name}/{parentId}/{path}/{weight}")
  public int editModule(@PathVariable String id,@PathVariable String name,@PathVariable Integer parentId,@PathVariable String path,@PathVariable Integer weight) {
      
      return modulesDao.editModule(id,name,parentId,path,weight);
      
  } 


  @ApiOperation(value="删除模块",notes = "删除模块")
  @DeleteMapping
  public int del( String id){

    return modulesDao.delModule(id);

  }


  @ApiOperation(value = "根据id获取的模块信息",notes = "根据id获取的模块信息")
  @ApiImplicitParam(name="id",value ="模块编号",required=true,paramType ="path")
  @GetMapping(value = "/{id}")

  public List<Modules> getModule(@PathVariable String id){
  
     

    
      return modulesDao.getModule(id);



  }



}